package com.ruoyi.assets.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.assets.dto.BasicDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.assets.domain.AssetBasic;
import com.ruoyi.assets.service.IAssetBasicService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 固定资产Controller
 * 
 * @author 孙帆科
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/basic")
public class AssetBasicController extends BaseController
{
    @Autowired
    private IAssetBasicService assetBasicService;

    /**
     * 查询固定资产列表
     */
    @RequiresPermissions("assets:basic:list")
    @GetMapping("/list")
    public TableDataInfo list(AssetBasic assetBasic)
    {
        startPage();
        List<AssetBasic> list = assetBasicService.selectAssetBasicList(assetBasic);
        return getDataTable(list);
    }

    /**
     * 导出固定资产列表
     */
    @RequiresPermissions("assets:basic:export")
    @Log(title = "固定资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetBasic assetBasic)
    {
        List<AssetBasic> list = assetBasicService.selectAssetBasicList(assetBasic);
        ExcelUtil<AssetBasic> util = new ExcelUtil<AssetBasic>(AssetBasic.class);
        util.exportExcel(response, list, "固定资产数据");
    }

    /**
     * 获取固定资产详细信息
     */
    @RequiresPermissions("assets:basic:query")
    @GetMapping(value = "/{basicId}")
    public AjaxResult getInfo(@PathVariable("basicId") Long basicId)
    {
        return success(assetBasicService.selectAssetBasicByBasicId(basicId));
    }

    /**
     * 获取固定资产详细信息
     * @param basicId
     */
//    @RequiresPermissions("assets:basic:query")
    @GetMapping(value = "/basicDetailsList/{basicId}")
    public AjaxResult basicDetailsList(@PathVariable("basicId") Long basicId)
    {
        return success(assetBasicService.basicDetailsList(basicId));
    }

    /**
     * 新增固定资产
     */
    @RequiresPermissions("assets:basic:add")
    @Log(title = "固定资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetBasic assetBasic)
    {
        return toAjax(assetBasicService.insertAssetBasic(assetBasic));
    }

    /**
     * 多表添加固定资产
     */
    @PostMapping("/additionAssets")
    public AjaxResult additionAssets(@RequestBody BasicDTO basicDTO)
    {
        return toAjax(assetBasicService.additionAssets(basicDTO));
    }

    /**
     * 修改固定资产
     */
    @RequiresPermissions("assets:basic:edit")
    @Log(title = "固定资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetBasic assetBasic)
    {
        return toAjax(assetBasicService.updateAssetBasic(assetBasic));
    }

    /**
     * 删除固定资产
     */
    @RequiresPermissions("assets:basic:remove")
    @Log(title = "固定资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{basicIds}")
    public AjaxResult remove(@PathVariable Long[] basicIds)
    {
        return toAjax(assetBasicService.deleteAssetBasicByBasicIds(basicIds));
    }
}
